#!/bin/bash

# 清屏并显示信息
clear
echo -e "小战云原创脚本官网：https://idc.sanxiaozhan.org/"
echo -e "小战云 为您提供稳定可靠的云服务 国内服务器40元起，海外服务器20元起"
sleep 5s


# 检查是否以超级用户权限运行
if [ "$EUID" -ne 0 ]; then
    echo "请以超级用户权限运行此脚本。"
    exit 1
fi

# 检查操作系统类型
if [ -f /etc/debian_version ]; then
    if [ -f /etc/lsb-release ]; then
        . /etc/lsb-release
        if [ "$DISTRIB_ID" == "Ubuntu" ]; then
            OS_TYPE="Ubuntu"
        else
            OS_TYPE="Debian"
        fi
    else
        OS_TYPE="Debian"
    fi
elif [ -f /etc/redhat-release ]; then
    OS_TYPE="RedHat"
else
    echo "不支持的操作系统。"
    exit 1
fi

# 更新包列表并安装中文语言包
if [ "$OS_TYPE" == "Debian" ] || [ "$OS_TYPE" == "Ubuntu" ]; then
    echo "更新包列表..."
    apt update
    echo "安装中文语言包..."
    apt install -y language-pack-zh-hans

    # 修改默认语言为中文
    echo "修改默认语言为中文..."
    echo "LANG=zh_CN.UTF-8" > /etc/default/locale
    echo "LANGUAGE=zh_CN:zh:en_US:en" >> /etc/default/locale

    # 重新配置语言环境
    echo "重新配置语言环境..."
    locale-gen zh_CN.UTF-8
    update-locale LANG=zh_CN.UTF-8

    # 提示用户重启
    read -p "语言包已安装，默认语言已更改为中文。是否执行重启？(yes/no): " answer
    if [ "$answer" == "yes" ]; then
        reboot
    else
        echo "重启已取消。"
    fi

elif [ "$OS_TYPE" == "RedHat" ]; then
    echo "更新包列表..."
    yum update -y
    echo "安装中文语言包..."
    yum install -y glibc-common

    # 修改默认语言为中文
    echo "修改默认语言为中文..."
    localectl set-locale LANG=zh_CN.UTF-8

    # 重新配置语言环境
    echo "重新配置语言环境..."
    source /etc/locale.conf
    echo "LANG=zh_CN.UTF-8" > /etc/locale.conf
    echo "LANGUAGE=zh_CN:zh:en_US:en" >> /etc/locale.conf

    # 提示用户重启
    read -p "语言包已安装，默认语言已更改为中文。是否执行重启？(yes/no): " answer
    if [ "$answer" == "yes" ]; then
        reboot
    else
        echo "重启已取消。"
    fi
fi

# 显示当前语言设置
echo "当前语言设置如下："
if [ "$OS_TYPE" == "Debian" ] || [ "$OS_TYPE" == "Ubuntu" ]; then
    cat /etc/default/locale
elif [ "$OS_TYPE" == "RedHat" ]; then
    cat /etc/locale.conf
fi
